package Wallpaper::Execute::ConfigTweak;
$VERSION = sprintf "%.3f", 1 + substr(q$Revision: 159 $,9)/1000;

package Wallpaper::Execute;

use Wallpaper::Configuration qw( %datastore );

=item * config_tweak

config_tweak has no parameters and no return value.

=cut

sub config_tweak {
    my ( $self, $display, $template, $output ) = @_;
    my $general_config = Wallpaper::Configuration->general;
    my $display_config = Wallpaper::Configuration->display( $display );

    my $colorscheme   = $datastore{ $display }{ 'scheme' };
    my $debug         = $general_config->{ 'debug' };
    my $this_function = ( caller( 0 ) )[3];

    print "$self : $this_function (2) Tweaking $output\n" if ( $debug ge "2" );

    # Read our template
    open( INPUT, "<" . $template );
    my @lines = <INPUT>;
    close INPUT;

    # Ande create our new configuration file.
    open( OUTPUT, ">" . $output );
    foreach my $line ( @lines ) {

        $line =~ s/_NORM_BASE_/$colorscheme->{'primary'}{'base'}/g;
        $line =~ s/_NORM_DARK_/$colorscheme->{'primary'}{'dark'}/g;
        $line =~ s/_NORM_PALE_/$colorscheme->{'primary'}{'pale'}/g;
        $line =~ s/_NORM_LPALE_/$colorscheme->{'primary'}{'lpale'}/g;

        $line =~ s/_WARM_BASE_/$colorscheme->{'warm'}{'base'}/g;
        $line =~ s/_WARM_DARK_/$colorscheme->{'warm'}{'dark'}/g;
        $line =~ s/_WARM_PALE_/$colorscheme->{'warm'}{'pale'}/g;
        $line =~ s/_WARM_LPALE_/$colorscheme->{'warm'}{'lpale'}/g;

        $line =~ s/_WARMER_BASE_/$colorscheme->{'warmer'}{'base'}/g;
        $line =~ s/_WARMER_DARK_/$colorscheme->{'warmer'}{'dark'}/g;
        $line =~ s/_WARMER_PALE_/$colorscheme->{'warmer'}{'pale'}/g;
        $line =~ s/_WARMER_LPALE_/$colorscheme->{'warmer'}{'lpale'}/g;

        $line =~ s/_WARMEST_BASE_/$colorscheme->{'warmest'}{'base'}/g;
        $line =~ s/_WARMEST_DARK_/$colorscheme->{'warmest'}{'dark'}/g;
        $line =~ s/_WARMEST_PALE_/$colorscheme->{'warmest'}{'pale'}/g;
        $line =~ s/_WARMEST_LPALE_/$colorscheme->{'warmest'}{'lpale'}/g;

        $line =~ s/_COOL_BASE_/$colorscheme->{'cool'}{'base'}/g;
        $line =~ s/_COOL_DARK_/$colorscheme->{'cool'}{'dark'}/g;
        $line =~ s/_COOL_PALE_/$colorscheme->{'cool'}{'pale'}/g;
        $line =~ s/_COOL_LPALE_/$colorscheme->{'cool'}{'lpale'}/g;

        $line =~ s/_COOLER_BASE_/$colorscheme->{'cooler'}{'base'}/g;
        $line =~ s/_COOLER_DARK_/$colorscheme->{'cooler'}{'dark'}/g;
        $line =~ s/_COOLER_PALE_/$colorscheme->{'cooler'}{'pale'}/g;
        $line =~ s/_COOLER_LPALE_/$colorscheme->{'cooler'}{'lpale'}/g;

        $line =~ s/_COOLEST_BASE_/$colorscheme->{'coolest'}{'base'}/g;
        $line =~ s/_COOLEST_DARK_/$colorscheme->{'coolest'}{'dark'}/g;
        $line =~ s/_COOLEST_PALE_/$colorscheme->{'coolest'}{'pale'}/g;
        $line =~ s/_COOLEST_LPALE_/$colorscheme->{'coolest'}{'lpale'}/g;

        $line =~ s/_COMP_BASE_/$colorscheme->{'comp'}{'base'}/g;
        $line =~ s/_COMP_DARK_/$colorscheme->{'comp'}{'dark'}/g;
        $line =~ s/_COMP_PALE_/$colorscheme->{'comp'}{'pale'}/g;
        $line =~ s/_COMP_LPALE_/$colorscheme->{'comp'}{'lpale'}/g;

        $line =~ s/_COMP_WARM_BASE_/$colorscheme->{'comp_warm'}{'base'}/g;
        $line =~ s/_COMP_WARM_DARK_/$colorscheme->{'comp_warm'}{'dark'}/g;
        $line =~ s/_COMP_WARM_PALE_/$colorscheme->{'comp_warm'}{'pale'}/g;
        $line =~ s/_COMP_WARM_LPALE_/$colorscheme->{'comp_warm'}{'lpale'}/g;

        $line =~ s/_COMP_WARMER_BASE_/$colorscheme->{'comp_warmer'}{'base'}/g;
        $line =~ s/_COMP_WARMER_DARK_/$colorscheme->{'comp_warmer'}{'dark'}/g;
        $line =~ s/_COMP_WARMER_PALE_/$colorscheme->{'comp_warmer'}{'pale'}/g;
        $line =~ s/_COMP_WARMER_LPALE_/$colorscheme->{'comp_warmer'}{'lpale'}/g;

        $line =~ s/_COMP_COOL_BASE_/$colorscheme->{'comp_cool'}{'base'}/g;
        $line =~ s/_COMP_COOL_DARK_/$colorscheme->{'comp_cool'}{'dark'}/g;
        $line =~ s/_COMP_COOL_PALE_/$colorscheme->{'comp_cool'}{'pale'}/g;
        $line =~ s/_COMP_COOL_LPALE_/$colorscheme->{'comp_cool'}{'lpale'}/g;

        $line =~ s/_COMP_COOLER_BASE_/$colorscheme->{'comp_cooler'}{'base'}/g;
        $line =~ s/_COMP_COOLER_DARK_/$colorscheme->{'comp_cooler'}{'dark'}/g;
        $line =~ s/_COMP_COOLER_PALE_/$colorscheme->{'comp_cooler'}{'pale'}/g;
        $line =~ s/_COMP_COOLER_LPALE_/$colorscheme->{'comp_cooler'}{'lpale'}/g;

        print OUTPUT "$line";
    } ## end foreach my $line ( @lines )
    close OUTPUT;

} ## end sub config_tweak

1;
